import 'package:boss/models/material.dart' as material;
import 'package:boss/provider/material_provider.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'widget/material_picker_browser.dart';

@RouterConfig(MaterialPickerPage.pageName)
class MaterialPickerPage extends StatefulWidget {
  static const pageName = '/materialPickerPage';

  @Autowired()
  final List<material.Material> selectedMaterials;

  const MaterialPickerPage({
    Key key,
    this.selectedMaterials,
  }) : super(key: key);

  @override
  _MaterialPickerPageState createState() => _MaterialPickerPageState('选择加料配菜');
}

class _MaterialPickerPageState extends BaseState<MaterialPickerPage> {
  _MaterialPickerPageState(String pageName) : super(pageName);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(
        title: '选择加料配菜',
      ),
      body: MaterialPickerBrowser(),
    );
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      var materialProvider = Provider.of<MaterialProvider>(
        context,
        listen: false,
      );
      materialProvider.setSelectedMaterials(selectedMaterials: widget.selectedMaterials);
    });
  }
}
